<?php

/**
 * @author aisyah
 * @copyright 2012
 */

include "../dao/database.php";
require_once "../../config/upload_file.php";

$class_db = new Database;
$fupload = new Upload_File($dir);

//$id = $_GET['id'];
$modul = $_GET['modul'];

switch($modul){
    
    case "user":
    
        $user_id = $_POST['id'];
        $username = $_POST['username'];
        $password = $_POST['password'];
        $reset_quest = $_POST['reset_quest'];
        $reset_answer = $_POST['reset_answer'];        
            
        $row = array('username'=>"$username",'password'=>"$password",
                    'reset_quest'=>"$reset_quest", 'reset_answer'=>"$reset_answer");   
        
        $update=$class_db->update('user',$row,'user_id='.$user_id);
        if($update){
            header('location:my_account.php?modul=user');
        }else{
            echo "gak berhasil update";
        }
    
    break;
    
    case "biodata":
        
        $customer_id = $_POST['id'];
        $name = $_POST['name'];
        $street = $_POST['street'];
        $kecamatan = $_POST['kecamatan'];
        $city = $_POST['city'];
        $province = $_POST['province'];
        $zip_code = $_POST['zip_code'];
        $telephone = $_POST['telephone'];  
        
        if(empty($_FILES['photo']['tmp_name'])){
            
            $row = array('name'=>"$name",'street'=>"$street",
                    'kecamatan'=>"$kecamatan",'city'=>"$city",
                    'province'=>"$province",'zip_code'=>"$zip_code",
                    'telephone'=>"$telephone");
                    
                    
                    
        }else{
            $fupload->upload_file('customer','photo');
            $image = $fupload->file_name;
            //$thumbnail = $fupload->thumbnail;
            $row = array('name'=>"$name",'street'=>"$street",
                    'kecamatan'=>"$kecamatan",'city'=>"$city",
                    'province'=>"$province",'zip_code'=>"$zip_code",
                    'telephone'=>"$telephone",'photo'=>"$image");
                    
                }
        
        $update=$class_db->update('customer',$row,'customer_id='.$customer_id);
        if($update){
            header('location:my_account.php?modul=biodata');
        }else{
            echo "gak berhasil update";
        }
    
    break;
    
    case "addbiodata":
        
        $user_id = $_POST['id'];
        $name = $_POST['name'];
        $street = $_POST['street'];
        $kecamatan = $_POST['kecamatan'];
        $city = $_POST['city'];
        $province = $_POST['province'];
        $zip_code = $_POST['zip_code'];
        $telephone = $_POST['telephone'];  
        
        if(empty($_FILES['photo']['tmp_name'])){
            
            $value = array("$name","$street",
                    "$kecamatan","$city",
                    "$province","$zip_code",
                    "$telephone", "$user_id");
            
            $row = 'name, street, kecamatan, city, province, zip_code, telephone,user_id';
                    
                    
        }else{
            $fupload->upload_file('customer','photo');
            $image = $fupload->file_name;
            $thumbnail = $fupload->thumbnail;
            $value = array("$name","$street",
                    "$kecamatan","$city",
                    "$province","$zip_code",
                    "$telephone", "$image", "$user_id");
            
            $row = 'name, street, kecamatan, city, province, zip_code, telephone, photo, user_id';
                    
                }
        
        $insert=$class_db->add('customer',$value,$row);
        if($insert){
            header('location:my_account.php?modul=biodata');
        }else{
            echo "gak berhasil update";
        }
    
    break;
    
    
}

?>